Skip to content

feat: add analytics event schema registry with emit-time validation - #985

Open
0xtrendz wants to merge 13 commits into
Pulsefy:mainfrom
0xtrendz:fix/issue-822-be-123-analytics-event-schema-registry-and
Open

0xtrendz wants to merge 13 commits into
Pulsefy:mainfrom
0xtrendz:fix/issue-822-be-123-analytics-event-schema-registry-and

Conversation

@0xtrendz

Copy link
Copy Markdown

Overview

This PR adds a versioned Analytics Event Schema Registry with emit-time validation for the backend analytics pipeline. Every analytics event now declares a schema in a central registry, events are validated before they are recorded, invalid events are rejected and counted, and the registry is exported in a machine-readable form that dashboards and downstream consumers can read. Breaking schema changes are caught in CI unless the schema version is incremented.

Related Issue

Changes

🧩 Schema Registry & Validation

  • [MODIFY] app/backend/src/analytics/analytics.service.ts

    • Introduces a central, versioned schema registry keyed by event name and schema version.
    • Validates every event against its declared schema at emit time; rejects malformed events instead of recording them.
    • Tracks rejected/invalid events with a counter for observability.
    • Emits a validation error path so producers get immediate, actionable feedback.
  • [MODIFY] app/backend/src/analytics/analytics.module.ts

    • Wires the registry and export service into the analytics module and exposes them for injection.
  • [ADD] app/backend/src/analytics/schema-export.service.ts

    • Exports the full registry (event names, versions, field definitions) in a consumer-readable form for dashboards and downstream consumers.
    • Provides a stable snapshot used by CI to detect breaking changes.
  • [ADD] CI compatibility guard

    • Compares the committed schema snapshot against the current registry; adding a required field or removing a field fails CI unless the schema version is incremented.
  • [ADD] Tests

    • Coverage for schema validation, rejection + counting of invalid events, registry export shape, and the version-bump CI guard.

Verification Results

npm test -- src/analytics
✅ 12/12 passed

Live acceptance check:
✅ All emitted events validated against a versioned schema
✅ Invalid events rejected and counted (rejection counter increments)
✅ Breaking change without version bump fails CI guard
✅ Registry export readable by dashboards/consumers
Acceptance Criteria Status
Every analytics event has a versioned schema in a central registry ✅ Central registry keyed by event name + schema version
Events are validated before being recorded; invalid events rejected and counted ✅ Emit-time validation with rejection counter
Adding a required field or removing a field fails CI unless version incremented ✅ Snapshot-based CI compatibility guard
The registry is exported in a form dashboards and consumers can read SchemaExportService emits consumer-readable registry snapshot

Closes #822

@Cedarich

Copy link
Copy Markdown
Contributor

Kindly resolve conflicts

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@0xtrendz Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BE-123: Analytics Event Schema Registry and Validation

2 participants